﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;




namespace WindowsFormsApplication1
{   
//public class WSounds

//{

//    [DllImport("WinMM.dll")]
//    public static extern bool PlaySound(string fname, int Mod, int flag);


//    // these are the SoundFlags we are using here, check mmsystem.h for more
//    public int SND_ASYNC = 0x0001; // play asynchronously
//    public int SND_FILENAME = 0x00020000; // use file name
//    public int SND_PURGE = 0x0040; // purge non-static events

 

//public void Play(string fname, int SoundFlags)

//{

//PlaySound(fname, 0, SoundFlags);

//}

 

//public void StopPlay()

//{

//PlaySound(null, 0, SND_PURGE);

//}

//}
public class Player
{
    
    private string Pcommand;
    private bool isOpen;

    [DllImport("winmm.dll")]
    private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);

    public Player()
    {

    }

    public void Close()
    {
        Pcommand = "close MediaFile";
        mciSendString(Pcommand, null, 0, IntPtr.Zero);
        isOpen = false;
    }


    public void Open(string sFileName)
    {
        Pcommand = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
        mciSendString(Pcommand, null, 0, IntPtr.Zero);
        isOpen = true;
    }


    public void Play(bool loop)
    {
        if (isOpen)
        {
            
            Pcommand = "play MediaFile";
            if (loop)
                Pcommand += " REPEAT";
            mciSendString(Pcommand, null, 0, IntPtr.Zero);
        }
    }


}

}
